<?php

/*
 * 通用模型
 */

class Common_model extends CI_Model {
    /*
     * 获取列表 
     */

    public function getData($table,$where=[]) {
        empty($where)?$query = $this->db->select('*')->get($table):$query = $this->db->select('*')->where($where)->get($table);
        return $query->result_array();
    }
    


    /*
     * 更新数据 
     */

    public function updateData($table, $where=[], $data) {
        empty($where)?$state = $this->db->update($table, $data):$state = $this->db->where($where)->update($table, $data);;
        return $state;
    }

    /*
     * 添加数据 
     */

    public function addData($table, $data) {
        $this->db->insert($table, $data);
        return $this->db->affected_rows() ? true : false;
    }

    /*
     * 删除数据
     */

    public function delData($table, $where) {
        $this->db->where($where)->delete($table);
        return $this->db->affected_rows() ? true : false;
    }

}
